<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
         
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="毕业年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsnj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="上下年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bn">
                <a-select-option v-for="i in bn" :key="i.id" :value="i.id">{{i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:16}" :xl="{span:8}" style="padding-top:29px;">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="exportEcl">导出</a-button>
            <a-button @click="queryParam = {};$refs.table.refresh()">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :pagination="false"
      :alert="{ show: true }"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
    </a-card>
    </div>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable
  },
  data () {
    return {
      advanced: true,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        zsnj: '',
        bn:'sbn'
      },
     
        bn:[
          {
              id:'sbn',
              name:'上半年'
          },
          {
              id:'xbn',
              name:'下半年'
          }
        ]
      ,
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '院系',
          dataIndex: 'ssyxmc'
        },
        {
          title: '硕士国内生全日制',
          dataIndex: 'ssgnsqrz'
        },
        {
          title: '硕士留学生',
          dataIndex: 'sslxs'
        },
        {
          title: '硕士共计',
          dataIndex: 'ssgj'
        },
        {
          title: '博士国内生全日制',
          dataIndex: 'bsgnsqrz'
        },
       {
         title: '博士留学生',
         dataIndex: 'bslxs'
       },
       {
         title: '博士共计',
         dataIndex: 'bsgj'
       }
      ],
      selectMenu: {
        yx: [] ,// 院系
        zy:[]
      },
       pagination:{
      	current:1
      },
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
          // 获取当前学年
        this.$api.base.getSchoolYear().then(res=>{
          this.queryParam.zsnj = res.data.masterAdmissionYear
           this.loadData()
        })
    },
    // 加载数据
     loadData(parameter = {}) {
      
       let params = Object.assign(this.queryParam, parameter)
       this.loading = true;
       this.$api.cultivate.degreeQuery(params).then(res => {
         // console.log(res)
         const pagination = { ...this.pagination
         };
         pagination.total = 0
         if (res.data && res.data.total) {
           pagination.total = res.data.total;
         }
         this.data = []
         this.pagination = pagination;
         if (res.data && res.data.length) {
           for(let i=0;i<res.data.length;i++){
           if(res.data[i].ssyxmc){
             
               Object.assign(res.data[i].countStu,res.data[i].countStu,{ssyxmc:res.data[i].ssyxmc})
               this.data.push(res.data[i].countStu)
        
             
            }
           }
         }
         console.log(this.data)
         console.log(res.data)
         this.loading = false;
       })
     },

    exportEcl(){
      this.$export('degree/xwsh/exportXwtj',this.queryParam)
    }
  }
  
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
